package com.example.studyllm.controller.rag;


import com.example.studyllm.bo.ChatBO;
import com.example.studyllm.component.ai.model.service.ChatUtils;
import com.example.studyllm.bo.StreamEmitter;
import com.example.studyllm.entity.rag.RagModel;
import com.example.studyllm.service.rag.RagModelService;
import com.example.studyllm.vo.base.PageResultVO;
import com.example.studyllm.vo.base.Result;
import com.example.studyllm.vo.base.SelectVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.List;


/**
 * @author kw
 * @since 2025-02-05 15:12:50.850253
 */
@RestController
@RequestMapping("/ragModel")
public class RagModelController {

    @Resource
    private RagModelService ragModelService;

    @Resource
    private ChatUtils chats;
    /**
     * 通过id查询
     */
    @GetMapping("/{id}")
    public Result<RagModel> getById(@PathVariable(value = "id") Integer id) {
        return Result.success(ragModelService.getById(id));
    }

    /**
     * 新增
     */
    @PostMapping("/")
    public Result save(@RequestBody RagModel ragModel) {
        return Result.success(ragModelService.addRagModel(ragModel));
    }

    /**
     * 通过id删除
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable(value = "id") String ids) {
        ragModelService.deleteByIds(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/")
    public Result updateById(@RequestBody RagModel ragModel) {
        return Result.success(ragModelService.updateRagModelById(ragModel));
    }

    /**
     * 分页查询
     */
    @GetMapping("/")
    public Result<PageResultVO<RagModel>> page(RagModel ragModel) {
        return Result.success(ragModelService.getPage(ragModel));
    }

    @GetMapping("/groupBySupplier")
    public Result<List<SelectVO>> groupBySupplier(){
        return Result.success(ragModelService.groupBySupplier());
    }


    @PostMapping(value = "/chat/completions")
    public SseEmitter completions(@RequestBody ChatBO req) {
        return chats.handler(new StreamEmitter(),  req);
    }

}